import { ModalForm, ProFormText } from '@ant-design/pro-form';
import React, { useEffect } from 'react';
type UpdateFormProps = {
  formValue: Partial<ADMIN.Role> | undefined;
  updateModalVisible: boolean;
  handleUpdateModalVisible: any;
  formRef: any;
  handleUpdate: (id: number | undefined, values: ADMIN.Role) => void;
};

const UpdateFrom: React.FC<UpdateFormProps> = (props) => {
  const { formValue, formRef, handleUpdate, updateModalVisible, handleUpdateModalVisible } = props;
  useEffect(() => {
    formRef.current?.resetFields();
  }, [formRef, formValue]);

  return (
    <ModalForm<ADMIN.Role>
      title="修改角色"
      width={500}
      visible={updateModalVisible}
      onVisibleChange={handleUpdateModalVisible}
      onFinish={async (values) => {
        handleUpdate(formValue?.id, values);
        return true;
      }}
      formRef={formRef}
      initialValues={formValue}
    >
      <>
        <ProFormText name="name" label="名称" />
        <ProFormText name="remark" label="标识" />
      </>
    </ModalForm>
  );
};

export default UpdateFrom;
